//
//  HLSubjectSectionView.m
//  HLAerospace
//
//  Created by hulian-ios on 17/9/20.
//  Copyright © 2017年 hulian-LB. All rights reserved.
//

#import "HLSubjectSectionView.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/UIImageView+WebCache.h>
#import "HLMoreCourse.h"
#import "HLCollect.h"

@interface HLSubjectSectionView ()

/** ImageView  */
@property (nonatomic ,strong) UIImageView *iconView;
/** title  */
@property (nonatomic ,strong) UILabel *title;
/** arrow  */
@property (nonatomic ,strong) UIImageView *arrow;
/** line  */
@property (nonatomic ,strong) UIView *line;

@end

@implementation HLSubjectSectionView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self setupUI];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
        self.userInteractionEnabled = YES;
        [self addGestureRecognizer:tap];
    }
    return self;
}


- (UIImageView *)iconView
{
    if (!_iconView ) {
        _iconView = [[UIImageView alloc] init];
    }
    return _iconView;
}

- (UILabel *)title
{
    if (!_title ) {
        _title = [[UILabel alloc] init];
        _title.backgroundColor = [UIColor clearColor];
        _title.textColor = HLRGB(60, 60, 60);
        _title.font = [UIFont systemFontOfSize:IS_IPHONE_5 ? 12: kMainTitleFontSize];
    }
    return _title;
}

- (UIImageView *)arrow
{
    if (!_arrow) {
        _arrow = [[UIImageView alloc]init];
        _arrow.image = [UIImage imageNamed:@"home_course_fold_arrow"];
    }
    return _arrow;
}

- (UIView *)line
{
    if (!_line) {
        _line = [[UIView alloc]init];
        _line.backgroundColor = HLRGB(235, 235, 235);
    }
    return _line;
}

- (void)setupUI
{
    [self addSubview:self.iconView];
    [self addSubview:self.title];
    [self addSubview:self.arrow];
    [self addSubview:self.line];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(10);
        make.height.equalTo(@(16));
        make.width.equalTo(@(16));
    }];
    
    [self.arrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self).offset(-10);
        make.height.equalTo(@(16));
        make.width.equalTo(@(9));
        
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.arrow.mas_left).offset(-10);
        make.left.equalTo(self.iconView.mas_right).offset(10);
        make.centerY.equalTo(self);
        make.height.equalTo(@(25));
        
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.left.equalTo(self);
        make.right.equalTo(self);
        make.height.equalTo(@(1));
        
    }];
}

- (void)setContentTitle:(NSString *)contentTitle
{
    _contentTitle = contentTitle;
    self.title.text = contentTitle;
    self.iconView.image = [UIImage imageNamed:contentTitle];
}

- (void)tap
{
    if ([_delegate respondsToSelector:@selector(subjectSectionView:didSelectedTitle:)]) {
        [_delegate subjectSectionView:self didSelectedTitle:self.contentTitle];
    }
}

@end
